package com.diqye.engine;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.diqye.db.model.XModel;
import com.diqye.engine.render.JsonRender;
import com.diqye.engine.render.Render;

public class Controller {

	protected HttpServletRequest request;
	protected HttpServletResponse response;
	protected XModel reqModel,params;
	public Render render;
	
	
	
	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	public XModel getReqModel() {
		return reqModel;
	}
	
	public XModel getParams(){
		if(params==null){
			params = reqModel.getModel("params");
		}
		return params;
	}

	public void setReqModel(XModel reqModel) {
		this.reqModel = reqModel;
	}

	public void render(Render render) {
		this.render = render;
	}
	
	public void render(Object o){
		this.render = new JsonRender(o);
	}
	
	public void renderErr(Object data){
		this.render = new JsonRender(Constant.errData(data));
	}
	public void renderOk(Object data){
		this.render = new JsonRender(Constant.okData(data));
	}
	
	
	

}
